package com.niit.TopN.SchoolTopN;

import com.niit.bean.SchoolBean;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class SchoolTopNMapper extends Mapper<LongWritable, Text, SchoolBean, NullWritable> {
    SchoolBean outKey = new SchoolBean();
    NullWritable outValue = NullWritable.get();

    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String[] fields = value.toString().split(",");
        String school = fields[1];
        String city = fields[8];
        String ActiveDays = fields[10];
        String other = fields[9];
        if (other == null || other.equals("否") || other.equals("")||
                city == null || city.equals("未知") || city.equals("")) {
            return; // 跳过这个记录，不进行处理
        }

        outKey.set(city,school, Long.parseLong(ActiveDays));
        context.write(outKey,outValue);


    }
}
